using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace sharpTV.Entities
{
	/// <summary>
	/// Strongly-typed collection for the EventX class.
	/// </summary>
    [Serializable]
	public partial class EventXCollection : ActiveList<EventX, EventXCollection>
	{	   
		public EventXCollection() {}
        
        /// <summary>
		/// Filters an existing collection based on the set criteria. This is an in-memory filter
		/// Thanks to developingchris for this!
        /// </summary>
        /// <returns>EventXCollection</returns>
		public EventXCollection Filter()
        {
            for (int i = this.Count - 1; i > -1; i--)
            {
                EventX o = this[i];
                foreach (SubSonic.Where w in this.wheres)
                {
                    bool remove = false;
                    System.Reflection.PropertyInfo pi = o.GetType().GetProperty(w.ColumnName);
                    if (pi.CanRead)
                    {
                        object val = pi.GetValue(o, null);
                        switch (w.Comparison)
                        {
                            case SubSonic.Comparison.Equals:
                                if (!val.Equals(w.ParameterValue))
                                {
                                    remove = true;
                                }
                                break;
                        }
                    }
                    if (remove)
                    {
                        this.Remove(o);
                        break;
                    }
                }
            }
            return this;
        }
		
		
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the sharpTV_Events table.
	/// </summary>
	[Serializable]
	public partial class EventX : ActiveRecord<EventX>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public EventX()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public EventX(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public EventX(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public EventX(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("sharpTV_Events", TableType.Table, DataService.GetInstance("sharpTVSubSonicProvider"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarEventId = new TableSchema.TableColumn(schema);
				colvarEventId.ColumnName = "EventId";
				colvarEventId.DataType = DbType.Int32;
				colvarEventId.MaxLength = 0;
				colvarEventId.AutoIncrement = true;
				colvarEventId.IsNullable = false;
				colvarEventId.IsPrimaryKey = true;
				colvarEventId.IsForeignKey = false;
				colvarEventId.IsReadOnly = false;
				colvarEventId.DefaultSetting = @"";
				colvarEventId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarEventId);
				
				TableSchema.TableColumn colvarEventUId = new TableSchema.TableColumn(schema);
				colvarEventUId.ColumnName = "EventUId";
				colvarEventUId.DataType = DbType.Guid;
				colvarEventUId.MaxLength = 0;
				colvarEventUId.AutoIncrement = false;
				colvarEventUId.IsNullable = true;
				colvarEventUId.IsPrimaryKey = false;
				colvarEventUId.IsForeignKey = false;
				colvarEventUId.IsReadOnly = false;
				
						colvarEventUId.DefaultSetting = @"(newid())";
				colvarEventUId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarEventUId);
				
				TableSchema.TableColumn colvarChannelUId = new TableSchema.TableColumn(schema);
				colvarChannelUId.ColumnName = "ChannelUId";
				colvarChannelUId.DataType = DbType.Int32;
				colvarChannelUId.MaxLength = 0;
				colvarChannelUId.AutoIncrement = false;
				colvarChannelUId.IsNullable = true;
				colvarChannelUId.IsPrimaryKey = false;
				colvarChannelUId.IsForeignKey = false;
				colvarChannelUId.IsReadOnly = false;
				colvarChannelUId.DefaultSetting = @"";
				colvarChannelUId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarChannelUId);
				
				TableSchema.TableColumn colvarName = new TableSchema.TableColumn(schema);
				colvarName.ColumnName = "Name";
				colvarName.DataType = DbType.String;
				colvarName.MaxLength = 2000;
				colvarName.AutoIncrement = false;
				colvarName.IsNullable = true;
				colvarName.IsPrimaryKey = false;
				colvarName.IsForeignKey = false;
				colvarName.IsReadOnly = false;
				
						colvarName.DefaultSetting = @"(N'')";
				colvarName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarName);
				
				TableSchema.TableColumn colvarTitle = new TableSchema.TableColumn(schema);
				colvarTitle.ColumnName = "Title";
				colvarTitle.DataType = DbType.String;
				colvarTitle.MaxLength = 2000;
				colvarTitle.AutoIncrement = false;
				colvarTitle.IsNullable = true;
				colvarTitle.IsPrimaryKey = false;
				colvarTitle.IsForeignKey = false;
				colvarTitle.IsReadOnly = false;
				
						colvarTitle.DefaultSetting = @"(N'')";
				colvarTitle.ForeignKeyTableName = "";
				schema.Columns.Add(colvarTitle);
				
				TableSchema.TableColumn colvarDescription = new TableSchema.TableColumn(schema);
				colvarDescription.ColumnName = "Description";
				colvarDescription.DataType = DbType.String;
				colvarDescription.MaxLength = 10;
				colvarDescription.AutoIncrement = false;
				colvarDescription.IsNullable = true;
				colvarDescription.IsPrimaryKey = false;
				colvarDescription.IsForeignKey = false;
				colvarDescription.IsReadOnly = false;
				
						colvarDescription.DefaultSetting = @"(N'')";
				colvarDescription.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDescription);
				
				TableSchema.TableColumn colvarDuration = new TableSchema.TableColumn(schema);
				colvarDuration.ColumnName = "Duration";
				colvarDuration.DataType = DbType.DateTime;
				colvarDuration.MaxLength = 0;
				colvarDuration.AutoIncrement = false;
				colvarDuration.IsNullable = true;
				colvarDuration.IsPrimaryKey = false;
				colvarDuration.IsForeignKey = false;
				colvarDuration.IsReadOnly = false;
				colvarDuration.DefaultSetting = @"";
				colvarDuration.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDuration);
				
				TableSchema.TableColumn colvarIsTradeMarked = new TableSchema.TableColumn(schema);
				colvarIsTradeMarked.ColumnName = "IsTradeMarked";
				colvarIsTradeMarked.DataType = DbType.Boolean;
				colvarIsTradeMarked.MaxLength = 0;
				colvarIsTradeMarked.AutoIncrement = false;
				colvarIsTradeMarked.IsNullable = true;
				colvarIsTradeMarked.IsPrimaryKey = false;
				colvarIsTradeMarked.IsForeignKey = false;
				colvarIsTradeMarked.IsReadOnly = false;
				
						colvarIsTradeMarked.DefaultSetting = @"((0))";
				colvarIsTradeMarked.ForeignKeyTableName = "";
				schema.Columns.Add(colvarIsTradeMarked);
				
				TableSchema.TableColumn colvarParentalControlId = new TableSchema.TableColumn(schema);
				colvarParentalControlId.ColumnName = "ParentalControlId";
				colvarParentalControlId.DataType = DbType.String;
				colvarParentalControlId.MaxLength = 10;
				colvarParentalControlId.AutoIncrement = false;
				colvarParentalControlId.IsNullable = true;
				colvarParentalControlId.IsPrimaryKey = false;
				colvarParentalControlId.IsForeignKey = false;
				colvarParentalControlId.IsReadOnly = false;
				colvarParentalControlId.DefaultSetting = @"";
				colvarParentalControlId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarParentalControlId);
				
				TableSchema.TableColumn colvarCreationDate = new TableSchema.TableColumn(schema);
				colvarCreationDate.ColumnName = "CreationDate";
				colvarCreationDate.DataType = DbType.DateTime;
				colvarCreationDate.MaxLength = 0;
				colvarCreationDate.AutoIncrement = false;
				colvarCreationDate.IsNullable = true;
				colvarCreationDate.IsPrimaryKey = false;
				colvarCreationDate.IsForeignKey = false;
				colvarCreationDate.IsReadOnly = false;
				
						colvarCreationDate.DefaultSetting = @"(getdate())";
				colvarCreationDate.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreationDate);
				
				TableSchema.TableColumn colvarOwner = new TableSchema.TableColumn(schema);
				colvarOwner.ColumnName = "Owner";
				colvarOwner.DataType = DbType.Guid;
				colvarOwner.MaxLength = 0;
				colvarOwner.AutoIncrement = false;
				colvarOwner.IsNullable = true;
				colvarOwner.IsPrimaryKey = false;
				colvarOwner.IsForeignKey = false;
				colvarOwner.IsReadOnly = false;
				colvarOwner.DefaultSetting = @"";
				colvarOwner.ForeignKeyTableName = "";
				schema.Columns.Add(colvarOwner);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["sharpTVSubSonicProvider"].AddSchema("sharpTV_Events",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("EventId")]
		[Bindable(true)]
		public int EventId 
		{
			get { return GetColumnValue<int>(Columns.EventId); }
			set { SetColumnValue(Columns.EventId, value); }
		}
		  
		[XmlAttribute("EventUId")]
		[Bindable(true)]
		public Guid? EventUId 
		{
			get { return GetColumnValue<Guid?>(Columns.EventUId); }
			set { SetColumnValue(Columns.EventUId, value); }
		}
		  
		[XmlAttribute("ChannelUId")]
		[Bindable(true)]
		public int? ChannelUId 
		{
			get { return GetColumnValue<int?>(Columns.ChannelUId); }
			set { SetColumnValue(Columns.ChannelUId, value); }
		}
		  
		[XmlAttribute("Name")]
		[Bindable(true)]
		public string Name 
		{
			get { return GetColumnValue<string>(Columns.Name); }
			set { SetColumnValue(Columns.Name, value); }
		}
		  
		[XmlAttribute("Title")]
		[Bindable(true)]
		public string Title 
		{
			get { return GetColumnValue<string>(Columns.Title); }
			set { SetColumnValue(Columns.Title, value); }
		}
		  
		[XmlAttribute("Description")]
		[Bindable(true)]
		public string Description 
		{
			get { return GetColumnValue<string>(Columns.Description); }
			set { SetColumnValue(Columns.Description, value); }
		}
		  
		[XmlAttribute("Duration")]
		[Bindable(true)]
		public DateTime? Duration 
		{
			get { return GetColumnValue<DateTime?>(Columns.Duration); }
			set { SetColumnValue(Columns.Duration, value); }
		}
		  
		[XmlAttribute("IsTradeMarked")]
		[Bindable(true)]
		public bool? IsTradeMarked 
		{
			get { return GetColumnValue<bool?>(Columns.IsTradeMarked); }
			set { SetColumnValue(Columns.IsTradeMarked, value); }
		}
		  
		[XmlAttribute("ParentalControlId")]
		[Bindable(true)]
		public string ParentalControlId 
		{
			get { return GetColumnValue<string>(Columns.ParentalControlId); }
			set { SetColumnValue(Columns.ParentalControlId, value); }
		}
		  
		[XmlAttribute("CreationDate")]
		[Bindable(true)]
		public DateTime? CreationDate 
		{
			get { return GetColumnValue<DateTime?>(Columns.CreationDate); }
			set { SetColumnValue(Columns.CreationDate, value); }
		}
		  
		[XmlAttribute("Owner")]
		[Bindable(true)]
		public Guid? Owner 
		{
			get { return GetColumnValue<Guid?>(Columns.Owner); }
			set { SetColumnValue(Columns.Owner, value); }
		}
		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(Guid? varEventUId,int? varChannelUId,string varName,string varTitle,string varDescription,DateTime? varDuration,bool? varIsTradeMarked,string varParentalControlId,DateTime? varCreationDate,Guid? varOwner)
		{
			EventX item = new EventX();
			
			item.EventUId = varEventUId;
			
			item.ChannelUId = varChannelUId;
			
			item.Name = varName;
			
			item.Title = varTitle;
			
			item.Description = varDescription;
			
			item.Duration = varDuration;
			
			item.IsTradeMarked = varIsTradeMarked;
			
			item.ParentalControlId = varParentalControlId;
			
			item.CreationDate = varCreationDate;
			
			item.Owner = varOwner;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varEventId,Guid? varEventUId,int? varChannelUId,string varName,string varTitle,string varDescription,DateTime? varDuration,bool? varIsTradeMarked,string varParentalControlId,DateTime? varCreationDate,Guid? varOwner)
		{
			EventX item = new EventX();
			
				item.EventId = varEventId;
			
				item.EventUId = varEventUId;
			
				item.ChannelUId = varChannelUId;
			
				item.Name = varName;
			
				item.Title = varTitle;
			
				item.Description = varDescription;
			
				item.Duration = varDuration;
			
				item.IsTradeMarked = varIsTradeMarked;
			
				item.ParentalControlId = varParentalControlId;
			
				item.CreationDate = varCreationDate;
			
				item.Owner = varOwner;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn EventIdColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn EventUIdColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn ChannelUIdColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn NameColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        public static TableSchema.TableColumn TitleColumn
        {
            get { return Schema.Columns[4]; }
        }
        
        
        
        public static TableSchema.TableColumn DescriptionColumn
        {
            get { return Schema.Columns[5]; }
        }
        
        
        
        public static TableSchema.TableColumn DurationColumn
        {
            get { return Schema.Columns[6]; }
        }
        
        
        
        public static TableSchema.TableColumn IsTradeMarkedColumn
        {
            get { return Schema.Columns[7]; }
        }
        
        
        
        public static TableSchema.TableColumn ParentalControlIdColumn
        {
            get { return Schema.Columns[8]; }
        }
        
        
        
        public static TableSchema.TableColumn CreationDateColumn
        {
            get { return Schema.Columns[9]; }
        }
        
        
        
        public static TableSchema.TableColumn OwnerColumn
        {
            get { return Schema.Columns[10]; }
        }
        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string EventId = @"EventId";
			 public static string EventUId = @"EventUId";
			 public static string ChannelUId = @"ChannelUId";
			 public static string Name = @"Name";
			 public static string Title = @"Title";
			 public static string Description = @"Description";
			 public static string Duration = @"Duration";
			 public static string IsTradeMarked = @"IsTradeMarked";
			 public static string ParentalControlId = @"ParentalControlId";
			 public static string CreationDate = @"CreationDate";
			 public static string Owner = @"Owner";
						
		}
		#endregion
		
		#region Update PK Collections
		
        #endregion
    
        #region Deep Save
		
        #endregion
	}
}
